from typing import List

from sqlalchemy_tool.base_crdu import BaseCrdu
from example.models import CategoryInfo, TypeInfo


class CategoryInfoCrdu(BaseCrdu[CategoryInfo]):
    @classmethod
    def get_by_name(cls, name) -> CategoryInfo:
        """通过name属性查询一条"""
        return cls.get_one(CategoryInfo.name == name)


class TypeInfoCrdu(BaseCrdu[TypeInfo]):
    @classmethod
    def get_by_name(cls, name) -> TypeInfo:
        """通过name属性查询一条"""
        return cls.get_one(TypeInfo.name == name)

    @classmethod
    def get_list_by_category(cls, category_id) -> List[TypeInfo]:
        """通过category_id属性查询所有"""
        return cls.list(TypeInfo.category_info == category_id)
